/**
 * @file cm_message_converter.h
 * @author jmdvirus
 * @date 2021-11-30 10:08:31
 */

#ifndef CM_MESSAGE_CONVERTER_H
#define CM_MESSAGE_CONVERTER_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifdef __cplusplus
}
#endif

#include "jsoncpp/json/json.h"
#include "cm_message_define.h"

class CMMessageConverterJson
{
  public:
    CMMessageConverterJson();

    ~CMMessageConverterJson();

    int load(const char *file);
    int load(std::string &data);

    std::string generateString();
    std::string responseString(int code, char *msg);

    std::string JsonValuetoString(Json::Value root);

    int setString(const char *key1, const char *key2, const char *value);
    int setInt(const char *key1, const char *key2, int value);
    int setInt64(const char *key1, const char *key2, int64_t value);
    int setDouble(const char *key1, const char *key2, double value);

    std::string getString(const char *key1, const char *key2);
    int getInt(const char *key1, const char *key2);
    int64_t getInt64(const char *key1, const char *key2);
    double getDouble(const char *key1, const char *key2);

    Json::Value &publicRoot()
    {
        return m_root;
    }

  protected:
    Json::Value &useRoot()
    {
        return m_root;
    }

  private:
    Json::Value m_root;
};

#endif // CM_MESSAGE_CONVERTER_H
